/*
 * Copyright (c) 2020 WildFireChat. All rights reserved.
 */

package com.cincc.cinccimdemo.ui.me.favorite.viewholder;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.cincc.cinccimdemo.R;
import com.cincc.cinccimdemo.common.FileUtils;
import com.cincc.im.model.CollectModel;
import com.cincc.im.util.Base64Util;

import org.json.JSONObject;

public class FavFileContentViewHolder extends FavContentViewHolder {
    ImageView fileIconImageView;
    TextView fileNameTextView;
    TextView fileSizeTextView;

    public FavFileContentViewHolder(@NonNull View itemView) {
        super(itemView);
        bindViews(itemView);
    }

    private void bindViews(View itemView) {
        fileIconImageView = itemView.findViewById(R.id.fileIconImageView);
        fileNameTextView = itemView.findViewById(R.id.fileNameTextView);
        fileSizeTextView = itemView.findViewById(R.id.fileSizeTextView);
    }

    @Override
    public void bind(Activity context, CollectModel item) {
        super.bind(context, item);
        try {
            String data = Base64Util.decodeToString(item.messageContent);
            JSONObject jsonObject = new JSONObject(data);
            String fileSize = FileUtils.getFileSize(jsonObject.getInt("fileSize"));
            fileNameTextView.setText(jsonObject.getString("fileName"));
            fileSizeTextView.setText(fileSize);
            fileIconImageView.setImageResource(FileUtils.getFileTypeImageResId(jsonObject.getString("fileName")));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onClick() {
        Toast.makeText(mContext, "暂不支持预览", Toast.LENGTH_SHORT).show();
    }
}
